{% load i18n %}
{% load rich_text %}
{% load money %}
{% load static %}
<div class="table-responsive">
    {% csrf_token %}
    <table class="table table-condensed transaction-list" data-url="{% if request.event %}{% url "plugins:banktransfer:import.action" event=request.event.slug organizer=request.organizer.slug %}{% else %}{% url "plugins:banktransfer:import.action" organizer=request.organizer.slug %}{% endif %}">
        <thead>
        <tr>
            <th></th>
            <th>{% trans "Date" %}</th>
            <th>{% trans "Payer and reference" %}</th>
            <th>{% trans "Amount" %}</th>
            <th>{% trans "Result" %}</th>
            <th>{% trans "Order" %}</th>
            <th></th>
        </tr>
        </thead>
        <tbody>
        {% for trans in list %}
            <tr data-id="{{ trans.id }}">
                <td class="actions">
                    {% if trans.order and trans.state == 'invalid' %}
                        <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="accept"
                                data-toggle="tooltip" title="{% trans "Accept anyway" %}" data-placement="right">
                            <span class="fa fa-check"></span>
                        </button>
                    {% elif trans.state == 'nomatch' %}
                        <input type="text" class="form-control" placeholder="{% trans "Order code" %}">
                        <button class="btn btn-default" type="button" name="action_{{ trans.id }}"
                                value="assign" data-toggle="tooltip" title="{% trans "Assign to order" %}"
                                data-placement="right">
                            <span class="fa fa-check"></span>
                        </button>
                    {% elif trans.state == 'error' %}
                        <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="retry"
                                data-toggle="tooltip" title="{% trans "Retry" %}" data-placement="right">
                            <span class="fa fa-refresh"></span>
                        </button>
                    {% elif trans.state == 'already' %}
                        <input type="text" class="form-control" placeholder="{% trans "Order code" %}">
                        <div class="btn-group" role="group">
                            <button class="btn btn-default" type="button" name="action_{{ trans.id }}"
                                    value="assign" data-toggle="tooltip" title="{% trans "Assign to order" %}"
                                    data-placement="right">
                                <span class="fa fa-check"></span>
                            </button>
                            <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="retry"
                                    data-toggle="tooltip" title="{% trans "Retry" %}" data-placement="right">
                                <span class="fa fa-refresh"></span>
                            </button>
                        </div>
                    {% endif %}
                </td>
                <td>
                    {% if trans.date_parsed is not None %}
                        {{ trans.date_parsed|date:"SHORT_DATE_FORMAT" }}
                    {% else %}
                        {{ trans.date }}
                    {% endif %}
                </td>
                <td>
                    <div class="clearfix">
                        {% if trans.payer %}
                            {{ trans.payer }}
                            <br>
                        {% endif %}
                        {% if trans.iban or trans.bic %}
                            {% if trans.iban %}
                                <em>{{ trans.iban }}</em>
                            {% endif %}
                            {% if trans.bic %}
                                <em>{{ trans.bic }}</em>
                            {% endif %}
                            <br>
                        {% endif %}
                    </div>
                    {{ trans.reference }}
                    <div class="comment-box" data-plain="{{ trans.comment }}">
                        <strong>{% trans "Comment:" %}</strong>
                        <span class="comment">{{ trans.comment|rich_text }}</span>
                        <a href="#" class="comment-modify btn btn-default btn-xs">
                            <span class="fa fa-edit"></span>
                        </a>
                    </div>
                </td>
                <td>{{ trans.amount|floatformat:2 }}</td>
                <td>
                    {% if trans.message %}
                        {% trans trans.message %}
                    {% elif trans.state == 'nomatch' %}
                        {% trans "No order code detected" %}
                    {% elif trans.state == 'invalid' %}
                        {% trans "Invalid for this order" %}
                    {% elif trans.state == 'error' %}
                        {% trans "Error while processing" %}
                    {% elif trans.state == 'valid' %}
                        {% trans "The order is already marked as paid" %}
                    {% elif trans.state == 'already' %}
                        {% trans "Order already paid" %}
                    {% endif %}
                </td>
                <td>
                    {% if trans.order %}
                        <a href="{% url "control:event.order" event=trans.order.event.slug organizer=request.organizer.slug code=trans.order.code %}"
                                data-toggle="tooltip" title="{{ trans.order.total|money:trans.order.event.currency }}">
                            {% if not request.event %}
                                {{ trans.order.event.slug|upper }}-{{ trans.order.code }}
                            {% else %}
                                {{ trans.order.code }}
                            {% endif %}
                        </a>
                    {% endif %}
                </td>
                <td class="discard">
                    <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="discard"
                            data-toggle="tooltip" title="{% trans "Discard" %}">
                        <span class="fa fa-trash"></span>
                    </button>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
